package org.jeecg.modules.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.ptCases.service.IPtCasesService;
import org.jeecg.modules.ptFirstdisease.entity.PtFirstdisease;
import org.jeecg.modules.ptFirstdisease.service.IPtFirstdiseaseService;
import org.jeecg.modules.ptSeconddisease.entity.PtSeconddisease;
import org.jeecg.modules.ptSeconddisease.service.IPtSeconddiseaseService;
import org.jeecg.modules.ptSeekmedical.entity.PtSeekmedical;
import org.jeecg.modules.ptSeekmedical.service.IPtSeekmedicalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/app/api")
public class AppSearchTaskApiController {

    @Autowired
    private IPtSeekmedicalService ptSeekmedicalService;
    //病例
    @Autowired
    private IPtCasesService ptCasesService;
    @Autowired
    private IPtFirstdiseaseService ptFirstdiseaseService;
    @Autowired
    private IPtSeconddiseaseService ptSeconddiseaseService;

    /**
     * 列表查询
     *
     * @param ptFirstdisease
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="科室分类-列表查询", notes="科室分类-列表查询")
    @PostMapping(value = "/firstdisease_list")
    public Result<List<PtFirstdisease>> firstdisease_list(PtFirstdisease ptFirstdisease) {
        QueryWrapper<PtFirstdisease> queryWrapper = new QueryWrapper<>();
        List<PtFirstdisease> pageList = ptFirstdiseaseService.list( queryWrapper);
        return Result.OK(pageList);
    }
    /**
     * 列表查询
     *
     * @param ptFirstdisease
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="症状分类-列表查询", notes="症状分类-列表查询")
    @PostMapping(value = "/seconddisease_list")
    public Result<List<PtSeconddisease>> seconddisease_list(PtFirstdisease ptFirstdisease) {
        QueryWrapper<PtSeconddisease> queryWrapper = new QueryWrapper<>();
        List<PtSeconddisease> pageList = ptSeconddiseaseService.list( queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 根据一级查询二级
     *
     * @param jsonObject
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="症状分类-列表查询", notes="症状分类-列表查询")
    @PostMapping(value = "/first_seconddisease")
    public Result<List<PtSeconddisease>> first_seconddisease(@RequestBody JSONObject jsonObject) {
        String fristId= jsonObject.getString("fristId");
        QueryWrapper<PtSeconddisease> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("firstdisease_id",fristId);
        List<PtSeconddisease> pageList = ptSeconddiseaseService.list(queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 根据一级查询任务
     *
     * @param jsonObject
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="根据一级查询任务-列表查询", notes="根据一级查询任务-列表查询")
    @PostMapping(value = "/first_task")
    public Result<List<PtSeekmedical>> first_task(@RequestBody JSONObject jsonObject) {
        String fristId= jsonObject.getString("fristId");
        QueryWrapper<PtSeekmedical> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sectionoffice_id",fristId);
        List<PtSeekmedical> ptSeekmedicals = ptSeekmedicalService.list(queryWrapper);
        return Result.OK(ptSeekmedicals);
    }

    /**
     * 根据二级分类查任务
     *
     * @param jsonObject
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="根据二级分类查任务", notes="根据二级分类查任务")
    @PostMapping(value = "/second_task")
    public Result<List<PtSeekmedical>> second_task(@RequestBody JSONObject jsonObject) {
        String secondId= jsonObject.getString("secondId");
        QueryWrapper<PtSeekmedical> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("taskclass_id",secondId);
        List<PtSeekmedical> ptSeekmedicals = ptSeekmedicalService.list(queryWrapper);
        return Result.OK(ptSeekmedicals);
    }
    /**
     * 任务搜索
     *
     * @param jsonObject
     * @return
     */
    //@AutoLog(value = "求医任务-分页列表查询")
    @ApiOperation(value="任务搜索", notes="任务搜索")
    @PostMapping(value = "/search_task")
    public Result<List<PtSeekmedical>> search_task(@RequestBody JSONObject jsonObject) {
        String taskTitle= jsonObject.getString("taskTitle");
        String creatTime= jsonObject.getString("creatTime");
        String recommend= jsonObject.getString("recommend");
        String sales= jsonObject.getString("sales");
        QueryWrapper<PtSeekmedical> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("taskclass_id",taskTitle);
        if(creatTime.equals("1")){
            queryWrapper.orderByDesc("creat_time");
        }else if (recommend.equals("1")){
            queryWrapper.eq("is_recommend","1");
        }else if (sales.equals("1")){
            queryWrapper.orderByDesc("task_views");
        }
        List<PtSeekmedical> ptSeekmedicals = ptSeekmedicalService.list(queryWrapper);
        return Result.OK(ptSeekmedicals);
    }
}
